/*
 * Item.java
 *
 * This class stores details about an item purchased and provides methods
 * to accept and display details of the same. It also computes the
 * net amount to be paid for an item purchased.
 *
 * 
 */

package com.javacore.day9.store;

import java.util.Scanner;

/**
 * Item is a class to accept and display information about items
 * purchased and calculate the price of the item purchased.
 * @author 
 */

public class Item {
    
    /**
     * Instance variable to store the item name.
     */
    String name;
    
    /**
     * Instance variable to store the percentage of discount.
     */
    static double discount = 20;
    
    /**
     * Instance variable to store the number of units of an item purchased.
     */
    int quantity;
    
    /**
     * Instance variable to store the basic price of an item.
     */
    float price;
    
    /**
     * Instance variable to calculate the total price of items ordered
     */
    float totalPrice;
    
    /**
     * Instance variable to store the price after discount.
     */
    double netTotal;
    
    
    
    /** Creates a new instance of Item */
    public Item() {
        name = "";
        quantity = 0;
        totalPrice = 0;
        price = 0;
        netTotal = 0;
    }
    
    /**
     * Method to accept details about the item purchased.
     */
    void setDetails() {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the name of the Item you want to purchase:");
        name = input.next();
        if(name.equalsIgnoreCase("Pencil")){
            price = 9.99f;
        } else if(name.equalsIgnoreCase("Pen")){
            price = 15.99f;
        } else if (name.equalsIgnoreCase("Marker")){
            price = 19.99f;
        }
        System.out.println("Enter the number of " + name + "s to purchase:");
        quantity = input.nextInt();
    }
    
    /**
     * Method to calculate the price of the item after discount.
     */
    void computePrice() {
        double totalDiscount = 0;
        totalPrice = price * quantity;
        totalDiscount = discount / 100 * totalPrice;
	netTotal = totalPrice - totalDiscount;
    }
    
    /**
     * Method to print details about an item purchased and its price.
     */
    public void displayDetails(){
        System.out.format(" %1$-15s %2$-15.2f %3$-15d %4$-15.2f %5$-15.2f\n",
                name, price, quantity,
                ((totalPrice - netTotal)/totalPrice) * 100, netTotal);
      
    }
    
    /**
     * Method to print the header for the invoice.
     */
    public static void displayHeader(){
        String header = String.format(" %1$-15s %2$-15s %3$-15s %4$-15s " +
                "%5$-15s", "Item Name", "Item Price($)", "Quantity", 
                "Discount(%)","Net Total($)");
        System.out.println(header);
        System.out.println("------------------------------" +
                "------------------------------------------");
    }
}